//-----------------------------------------------------------------------------
// Name: Vaccine.cpp
// Auth: Paul Godfrey
// Desc: Draws a Vaccine
//-----------------------------------------------------------------------------

#include "Vaccine.h"

#include "SharedConstants.h"

#include "corona/corona.h"

#include <GL/glut.h>
#include <math.h>

//-----------------------------------------------------------------------------
// Globals:
//-----------------------------------------------------------------------------
cVaccine gVaccine;

//-----------------------------------------------------------------------------
// Functions:
//-----------------------------------------------------------------------------
cVaccine* GetVaccine()
{
	return &gVaccine;
}

//-----------------------------------------------------------------------------
// class cVaccine:
//-----------------------------------------------------------------------------
cVaccine::cVaccine()
{
	mXPosition = 0;
	mYPosition = 0;
	mZPosition = 0,
	mYaw = 0;
	mPitch = 0;
}

cVaccine::~cVaccine()
{
}

//Draws the vaccine syringe
void cVaccine::Draw(float x, float y, float z, float ya, float p)
{

	mXPosition=x;
	mYPosition=y;
	mZPosition=z;
	mYaw=ya;
	mPitch=p;

	glPushMatrix();
	glTranslatef(mXPosition, mYPosition-.5f, mZPosition);
	//glTranslatef(mXPosition, mYPosition, mZPosition);
	glRotatef( mYaw-90, 0.0f, 1.0f, 0.0f );
	glRotatef( mPitch, 0.0f, 0.0f, 1.0f );

	glPushMatrix();
	//glTranslatef(0.3f,0.0f, 0.0f);


	GLUquadricObj *pObj;

	pObj = gluNewQuadric();
	gluQuadricDrawStyle(pObj, GLU_FILL); //this makes it solid
	gluQuadricNormals( pObj, GLU_SMOOTH );


	//Needle
	glPushMatrix();
		glColor4f( 0.75f, 0.75f, 0.75f, 1.0f );

		glTranslatef( 0.4f, 0.0f, 0.0f );

		glRotatef( 90.0f, 0.0f, 1.0f, 0.0f );

		gluCylinder( pObj, 0.005, 0.00f, 0.45f, 10, 10 );
		//glutSolidCone(0.05f, 0.05f, 10,10);
		//glutSolidCylinder(0.05f, 0.25f, 10, 10);
	glPopMatrix();

	//Ends of main tube
	glPushMatrix();
			glColor4f( 0.9f, 0.9f, .9f, 1.0f );
	//Right Side
		glTranslatef( 0.4f, 0.0f, 0.0f );
		glDisable(GL_CULL_FACE);	
		glBegin(GL_TRIANGLE_FAN);
			glVertex3f(0.0f, 0.0f, 0.0f);
			for (int i = 0; i <= 100; ++i)
			{
				float y = cos(kPi / 4.0f * i) * 0.05f;
				float z = sin(kPi / 4.0f * i) * 0.05f;
				glVertex3f(0.0f, y, z);
			}
		glEnd();
	//Left Side
		glBegin(GL_TRIANGLE_FAN);
			glVertex3f(-0.4f, 0.0f, 0.0f);
			for (int i = 0; i <= 100; ++i)
			{
				float y = cos(kPi / 4.0f * i) * 0.05f;
				float z = sin(kPi / 4.0f * i) * 0.05f;
				glVertex3f(-0.4f, y, z);
			}
		glEnd();
		glEnable(GL_CULL_FACE);

	glPopMatrix();

	//End of liquid
	glPushMatrix();
		glColor4f( 0.0f, 0.75f, 0.1f, .75f );
		glDisable(GL_CULL_FACE);	
		glBegin(GL_TRIANGLE_FAN);
			glVertex3f(0.2f, 0.0f, 0.0f);
			for (int i = 0; i <= 100; ++i)
			{
				float y = cos(kPi / 4.0f * i) * 0.045f;
				float z = sin(kPi / 4.0f * i) * 0.045f;
				glVertex3f(0.2f, y, z);
			}
		glEnd();
		glEnable(GL_CULL_FACE);
	glPopMatrix();
		
	//Plunger end touching liquid
	glPushMatrix();
		glColor4f( 0.6f, 0.6f, 0.6f, 1.0f );
		glDisable(GL_CULL_FACE);	
		glBegin(GL_TRIANGLE_FAN);
			glVertex3f(0.19f, 0.0f, 0.0f);
			for (int i = 0; i <= 100; ++i)
			{
				float y = cos(kPi / 4.0f * i) * 0.045f;
				float z = sin(kPi / 4.0f * i) * 0.045f;
				glVertex3f(0.19f, y, z);
			}
		glEnd();
		glEnable(GL_CULL_FACE);
	glPopMatrix();

	//Plunger end
	glPushMatrix();
		glColor4f( 0.6f, 0.6f, 0.6f, 1.0f );

		glTranslatef( 0.17f, 0.0f, 0.0f );

		glRotatef( 90.0f, 0.0f, 1.0f, 0.0f );

		gluCylinder( pObj, 0.045f, 0.045f, 0.02f, 10, 10 );
		//glutSolidCone(0.05f, 0.05f, 10,10);
		//glutSolidCylinder(0.05f, 0.25f, 10, 10)
	glPopMatrix();

	//Plunger end not touching liquid
	glPushMatrix();
		glColor4f( 0.6f, 0.6f, 0.6f, 1.0f );
		glDisable(GL_CULL_FACE);	
		glBegin(GL_TRIANGLE_FAN);
			glVertex3f(0.17f, 0.0f, 0.0f);
			for (int i = 0; i <= 100; ++i)
			{
				float y = cos(kPi / 4.0f * i) * 0.045f;
				float z = sin(kPi / 4.0f * i) * 0.045f;
				glVertex3f(0.17f, y, z);
			}
		glEnd();
		glEnable(GL_CULL_FACE);
	glPopMatrix();

	//Plunger thin
	glPushMatrix();
		glColor4f( 0.6f, 0.6f, 0.6f, 1.0f );

		glTranslatef( -0.2f, 0.0f, 0.0f );

		glRotatef( 90.0f, 0.0f, 1.0f, 0.0f );

		gluCylinder( pObj, 0.01f, 0.01f, 0.38f, 10, 10 );
		//glutSolidCone(0.05f, 0.05f, 10,10);
		//glutSolidCylinder(0.05f, 0.25f, 10, 10)
	glPopMatrix();

		//Plunger end outside, closer to main tube
	glPushMatrix();
		glColor4f( 0.6f, 0.6f, 0.6f, 1.0f );
		glDisable(GL_CULL_FACE);	
		glBegin(GL_TRIANGLE_FAN);
			glVertex3f(-0.2f, 0.0f, 0.0f);
			for (int i = 0; i <= 100; ++i)
			{
				float y = cos(kPi / 4.0f * i) * 0.03f;
				float z = sin(kPi / 4.0f * i) * 0.03f;
				glVertex3f(-0.2f, y, z);
			}
		glEnd();
		glEnable(GL_CULL_FACE);
	glPopMatrix();

	//Plunger outer end
	glPushMatrix();
		glColor4f( 0.6f, 0.6f, 0.6f, 1.0f );

		glTranslatef( -0.21f, 0.0f, 0.0f );

		glRotatef( 90.0f, 0.0f, 1.0f, 0.0f );

		gluCylinder( pObj, 0.03f, 0.03f, 0.01f, 10, 10 );
		//glutSolidCone(0.05f, 0.05f, 10,10);
		//glutSolidCylinder(0.05f, 0.25f, 10, 10)
	glPopMatrix();

			//Plunger end outside, further main tube
	glPushMatrix();
		glColor4f( 0.6f, 0.6f, 0.6f, 1.0f );
		glDisable(GL_CULL_FACE);	
		glBegin(GL_TRIANGLE_FAN);
			glVertex3f(-0.21f, 0.0f, 0.0f);
			for (int i = 0; i <= 100; ++i)
			{
				float y = cos(kPi / 4.0f * i) * 0.03f;
				float z = sin(kPi / 4.0f * i) * 0.03f;
				glVertex3f(-0.21f, y, z);
			}
		glEnd();
		glEnable(GL_CULL_FACE);
	glPopMatrix();

	//Inner Glass tube
	glPushMatrix();
		glColor4f( 0.0f, 0.75f, 0.1f, .75f );

		glTranslatef( 0.2f, 0.0f, 0.0f );

		glRotatef( 90.0f, 0.0f, 1.0f, 0.0f );

		gluCylinder( pObj, 0.045f, 0.045f, 0.2f, 10, 10 );
		//glutSolidCone(0.05f, 0.05f, 10,10);
		//glutSolidCylinder(0.05f, 0.25f, 10, 10)
	glPopMatrix();


	//OuterGlassTube
	glPushMatrix();
		glColor4f( 1.0f, 1.0f, 1.0f, 0.25f );

		//glTranslatef( 0.0f, 0.0875f, 0.0f );

		glRotatef( 90.0f, 0.0f, 1.0f, 0.0f );

		gluCylinder( pObj, 0.05f, 0.05f, 0.4f, 10, 10 );
		gluCylinder( pObj, 0.045f, 0.045f, 0.4f, 10, 10 );
		//glutSolidCone(0.05f, 0.05f, 10,10);
		//glutSolidCylinder(0.05f, 0.25f, 10, 10);
	gluDeleteQuadric(pObj);

	glPopMatrix();
	glPopMatrix();
	glPopMatrix();
}